/**
 * @description **获取cookie值；默认以json数组格式返回所有cookie；也可获取指定cookie值**
 * @param {string} [cookieName='all'] - cookie名
 * @returns cookie值
 * @example
 *
 * ```js
 * cookieGet()
 * // return {name:'tom',age:'18'}
 * ```
 * @example
 *
 * ```js
 * cookieGet('name')
 * // return 'tom'
 * ```
 * 
 */
const cookieGet=(cookieName='all')=>{
    let strCookie = document.cookie;
    let arrCookie = strCookie.split("; ");
    
    // 将cookie转为json数组
    let Arr={};
    for(let i=0; i<arrCookie.length; i++){
        let arrCell=arrCookie[i].split("=");
        // 解码及赋值
        Arr[arrCell[0]]=unescape(arrCell[1]);
    }

    if(cookieName=='all'){
        // 默认返回所有cookie的json数组
        return Arr;
    }else{
        //返回指定cookie值
        for(let name in Arr){
            if(name==cookieName){
                return Arr[name];
            }
        }
    }
}

export default cookieGet;